/*
 * @Author: xiawei 1243162387@qq.com
 * @Date: 2024-03-28 16:26:53
 * @LastEditors: xiawei 1243162387@qq.com
 * @LastEditTime: 2024-03-29 08:28:01
 */
import inquirer from'inquirer';
import {execa} from 'execa';
import {config} from './config.js'

inquirer
  .prompt([
    {
      name: 'buildPackage',
      type: 'checkbox',
      message: '请选择要打包的应用',
      choices: Object.keys(config).map((key) => {
        const { name_cn, packageName } = config[key];
        return {
          name: `${name_cn}(${packageName})`,
          value: key,
        };
      })
    }
  ])
  .then(async (answers) => {
    Promise.all(answers.buildPackage.map((item) => new Promise((resolve) => {
      execa('npm', ['run', 'build'], {
        cwd: `./apps/${item}`,
        stdio: 'inherit',
      }).then(() => {
        resolve();
      });
    })))
  });